import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import { setupStore } from '@/store'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import enUs from 'element-plus/dist/locale/en.mjs'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import '@/styles/global.scss'
import DataVVue3 from '@kjgl77/datav-vue3'
import i18n from '@/locales'
import { setupElIcons, setupPermission } from "@/plugins";
import ButtonGroup from '@/components/ButtonGroup/index.vue'
import permission from '@/directives/permission'

const app = createApp(App)

import SvgIcon from '@/components/SvgIcon/index.vue'
app.component('svg-icon', SvgIcon)

import mavonEditor from "mavon-editor";
import "mavon-editor/dist/css/index.css";
app.use(mavonEditor);

// 初始化权限
setupStore(app)

app.use(router)
app.use(DataVVue3)
app.use(i18n)

// 根据当前语言设置 Element Plus 的本地化
const locale = localStorage.getItem('locale') || 'zh-CN'
const elementLocale = locale === 'zh-CN' ? zhCn : enUs
app.use(ElementPlus, {
  locale: elementLocale
})

app.component('ButtonGroup', ButtonGroup)

setupPermission()
setupElIcons(app)

app.directive('permission', permission)

app.mount('#app') 